import React, { Component } from 'react'
import Header from '../../components/Header/Header'
import {Form,Button,Input,Toast} from 'antd-mobile'
import './Login.less'
import {reqlogin} from '../../request/api'
export default class Login extends Component {
    constructor(){
        super();
        this.state={
            user:{
                phone:"",
                password:""
            }
        }
    };
    login=()=>{
        reqlogin(this.state.user).then(d=>{
            if(d.data.code===200){
                Toast.show({
                    content:d.data.msg
                })
                sessionStorage.setItem("isLogin",JSON.stringify(d.data.list));
                this.props.history.push("/index/home");
            }else{
                Toast.show({
                    content:d.data.msg
                })
            }
        })
    };
    render() {
        const { user } = this.state;
        return (
            <div>
                <Header title="登录" register></Header>
                <Form layout="horizontal">
                    <Form.Item label='手机号'>
                        <Input placeholder='请输入姓名' clearable onChange={(e)=>this.setState({user:{...user,phone:e}})}/>
                    </Form.Item>

                    <Form.Item label='密码'>
                        <Input placeholder='请输入密码' clearable onChange={(e)=>this.setState({user:{...user,password:e}})}/>
                    </Form.Item>
                </Form>
                <div className="text-center">
                    <Button color="primary" onClick={this.login}>登录</Button>
                </div>
            </div>
        )
    }
}
